// //
// Copyright (C) 2006 Pilitsyn Vasiliy <nexus@ablogic.ru>
#ifndef __VIEWENGINE_H
#define __VIEWENGINE_H


#include <qcanvas.h>
#include <qimage.h>
#include <qtooltip.h>
#include <qsqldatabase.h>
#include <qsqldatabase.h>
#include <qmainwindow.h>


#include "diagramline.h"
#include "devitem.h"
#include "cmdconsole.h"


static const int ItemRtti = 1001;
static const int lineRtti = 1002;

class ViewEngine : public QCanvasView
{
   Q_OBJECT
   public:
      ViewEngine( QCanvas* canvas, QWidget* parent );
      ~ViewEngine();
      void rescale();
      void setAllSelectMoveFasle( bool );
      bool ShowResultQuery();
      QString getTextMSGObjects();
      bool readFile( const QString &fileName );
      bool writeFile( const QString &fileName );


      bool inportMapFromDB();

     bool modified;
     void clear();

     void        setSelect( const bool &select )         { choiceMap = select; }
     const      bool& isSelect() const { return choiceMap; }
     const      QString& isFileName() const { return fullFileName; }
     void        setFileName( const QString &fname )         { fullFileName = fname; }
     void        setColorsFont( const QString &,  const QString &, const QFont &, const QString &, const QString & );
     void        setNumberRetries( int & );
     int           NumberRetries;

     QString colorBackGround;
     QString colorLinesColor;
     QString colorTextColor;
     QString colorSelectedColor;

     bool DeviceMapBold;
     QString DeviceMapFont;
     bool DeviceMapItalic;
     int DeviceMapPointSize;
     int DeviceMapWeight;

     QString dbdriver;
     QString dbaddress;
     QString dbname;
     QString dbuser;
     QString dbpassword;
     QString dbCodepage;

     QFont font;

   public slots:
      void addLine();
      void deleteDevice();
      void deleteLine();
      void configdevice();
      void pingDevice();
      void tracerouteIP();
      void pingall();
      void upgWarningTimer();

   protected:
      void resizeEvent( QResizeEvent* );
      void contentsMouseMoveEvent( QMouseEvent* );
      void contentsMousePressEvent( QMouseEvent* );
      void contentsMouseReleaseEvent( QMouseEvent* );
      void contentsMouseObjectMenu( QMouseEvent* );
      void contentsMouseDoubleClickEvent( QMouseEvent* );

   private:
      void selectItem( DevItem* );
      void selectLine( DiagramLine* );
      void updateInformation();
      void addItem( QCanvasItem* );
      void get_lines();
      QSize showSizeMap();
      QString fullFileName;

      QPopupMenu* contextMenu;
      bool          choiceMap;
      bool          pressed;
      bool          readyDrawtLine;
      int              startX;
      int              startY;
      QPoint       selectedPos;
      DevItem*   selected;
      DiagramLine* selectedLine;
      QCanvasText* devicePos;
      QCanvasText* deviceSize;
      QCanvasText* deviceName;
      QCanvasText* deviceN;
      QCanvasItem *activeItem;
      Shell* shell;


};
#endif
